package com.CountDownTatch;

import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

/**
 * Created by apple on 17/9/29.
 */
public abstract class BaseHealth implements Callable<Boolean> {
    private CountDownLatch cdl;
    private String serverName;
    private boolean flag;

    public BaseHealth(CountDownLatch cdl, String serverName) {
        this.cdl = cdl;
        this.serverName = serverName;
    }

    @Override
    public Boolean call() throws Exception{
        try{
            service();
            return true;
        }catch(Throwable e){
            e.printStackTrace(System.err);
            return false;
        }finally {
            if(cdl != null)
                cdl.countDown();
        }
    }

    public abstract void service();

    public CountDownLatch getCdl() {
        return cdl;
    }

    public void setCdl(CountDownLatch cdl) {
        this.cdl = cdl;
    }

    public String getServerName() {
        return serverName;
    }

    public void setServerName(String serverName) {
        this.serverName = serverName;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }



}
